/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hitechbangla.fctu.form;

import com.hitechbangla.fctu.base.PressedButtonEnum;
import com.hitechbangla.fctu.base.aircraft.Aircraft;
import com.hitechbangla.fctu.base.radar.EpmType;
import com.hitechbangla.fctu.base.radar.Radar;
import fctu.simulator.HTB_MAIN;
import java.util.List;

/**
 *
 * @author Asus
 */
public class AddEPM extends javax.swing.JFrame {

    /**
     * Creates new form AddEPM
     */
    Radar radar;
    Aircraft aircraft;
    
    public AddEPM(Aircraft ac, Radar radar) {
	aircraft = ac;
	this.radar = radar;
	//System.out.println("EPM by ratan");
	initComponents();
    }


    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btn_EpmSB = new javax.swing.JButton();
        btn_EpmSLS = new javax.swing.JButton();
        btn_EpmFA = new javax.swing.JButton();
        btn_None = new javax.swing.JButton();
        btn_EpmMTI = new javax.swing.JButton();
        btn_EpmPLD = new javax.swing.JButton();
        btn_EpmPRFD = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        btn_EpmSB.setText("SB");
        btn_EpmSB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_EpmSBActionPerformed(evt);
            }
        });

        btn_EpmSLS.setText("SLS");
        btn_EpmSLS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_EpmSLSActionPerformed(evt);
            }
        });

        btn_EpmFA.setText("FA");
        btn_EpmFA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_EpmFAActionPerformed(evt);
            }
        });

        btn_None.setText("None");
        btn_None.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_NoneActionPerformed(evt);
            }
        });

        btn_EpmMTI.setText("MTI");
        btn_EpmMTI.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_EpmMTIActionPerformed(evt);
            }
        });

        btn_EpmPLD.setText("PLD");
        btn_EpmPLD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_EpmPLDActionPerformed(evt);
            }
        });

        btn_EpmPRFD.setText("PRFD");
        btn_EpmPRFD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_EpmPRFDActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(63, 63, 63)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btn_EpmFA, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btn_EpmMTI, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE))
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btn_None, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btn_EpmPLD, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btn_EpmSLS, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(26, 26, 26)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(btn_EpmSB, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE)
                            .addComponent(btn_EpmPRFD, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(88, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(44, 44, 44)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btn_EpmFA)
                    .addComponent(btn_EpmSLS)
                    .addComponent(btn_EpmSB))
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btn_EpmMTI)
                    .addComponent(btn_EpmPLD)
                    .addComponent(btn_EpmPRFD))
                .addGap(29, 29, 29)
                .addComponent(btn_None)
                .addContainerGap(127, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btn_EpmSBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_EpmSBActionPerformed
        // TODO add your handling code here:

//        ac.setEcmType(EcmType.SPOT);
//        //Runnable run =
//        Thread th = new Thread(new ECMNotifier(ac));
//        th.start();

	radar.setEpmType(EpmType.SB);
    }//GEN-LAST:event_btn_EpmSBActionPerformed

    private void btn_EpmSLSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_EpmSLSActionPerformed
        // TODO add your handling code here:

//        ac.setEcmType(EcmType.SPOT);
//        //Runnable run =
//        Thread th = new Thread(new ECMNotifier(ac));
//        th.start();

    }//GEN-LAST:event_btn_EpmSLSActionPerformed

    private void btn_EpmFAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_EpmFAActionPerformed
        // TODO add your handling code here:
        //set aircraft ecm type
        //notify other radars --- do it in a separate theread
	
//        ac.setEcmType(EcmType.SPOT);
//        //Runnable run =
//        Thread th = new Thread(new ECMNotifier(ac));
//        th.start();
	radar.setEpmType(EpmType.FA);
	
    }//GEN-LAST:event_btn_EpmFAActionPerformed

    private void btn_EpmMTIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_EpmMTIActionPerformed
        // TODO add your handling code here:

//        ac.setEcmType(EcmType.DECEPTION);
//        //Runnable run =
//        Thread th = new Thread(new ECMNotifier(ac));
//        th.start();
    }//GEN-LAST:event_btn_EpmMTIActionPerformed

    private void btn_EpmPLDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_EpmPLDActionPerformed
        // TODO add your handling code here:

//        ac.setEcmType(EcmType.CHAFF);
//        //Runnable run =
//        Thread th = new Thread(new ECMNotifier(ac));
//        th.start();
	radar.setEpmType(EpmType.PLD);
    }//GEN-LAST:event_btn_EpmPLDActionPerformed

    private void btn_NoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_NoneActionPerformed
        // TODO add your handling code here:

	radar.setEpmType(EpmType.NONE);
    }//GEN-LAST:event_btn_NoneActionPerformed

    private void btn_EpmPRFDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_EpmPRFDActionPerformed
        // TODO add your handling code here:
	
	radar.setEpmType(EpmType.PRFD);
    }//GEN-LAST:event_btn_EpmPRFDActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
	/* Set the Nimbus look and feel */
	//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
	 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
	 */
	try {
	    for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
		if ("Nimbus".equals(info.getName())) {
		    javax.swing.UIManager.setLookAndFeel(info.getClassName());
		    break;
		}
	    }
	} catch (ClassNotFoundException ex) {
	    java.util.logging.Logger.getLogger(AddEPM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
	} catch (InstantiationException ex) {
	    java.util.logging.Logger.getLogger(AddEPM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
	} catch (IllegalAccessException ex) {
	    java.util.logging.Logger.getLogger(AddEPM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
	} catch (javax.swing.UnsupportedLookAndFeelException ex) {
	    java.util.logging.Logger.getLogger(AddEPM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
	}
	//</editor-fold>

	/* Create and display the form */
	java.awt.EventQueue.invokeLater(new Runnable() {
	    public void run() {
		new AddEPM(null,null).setVisible(true);
	    }
	});
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_EpmFA;
    private javax.swing.JButton btn_EpmMTI;
    private javax.swing.JButton btn_EpmPLD;
    private javax.swing.JButton btn_EpmPRFD;
    private javax.swing.JButton btn_EpmSB;
    private javax.swing.JButton btn_EpmSLS;
    private javax.swing.JButton btn_None;
    // End of variables declaration//GEN-END:variables

    class EPMNotifier implements Runnable{
	Aircraft ac;
	public EPMNotifier(Aircraft ac) {
	    this.ac = ac;
	}
	
	@Override
	public void run() {
	    //throw new UnsupportedOperationException("Not supported yet.");
	    HTB_MAIN.gameScene.HTBParent.lastPressedButton = PressedButtonEnum.NONE;
	    List<Radar> radarList = HTB_MAIN.gameScene.radarList;
	    for(Radar radar : radarList){
		//radar.notify(ac);
		radar.notifyRadarForEpm(ac);
	    }//end for
	}//end of run
    
    }//end of ecm notifier class

}
